package com.daz.student.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;










import com.daz.common.jsonToMap.JsonToMap;
import com.daz.common.publicDict.pojo.SystemParam;
import com.daz.common.publicDict.pojo.publicDictPojo;
import com.daz.common.publicDict.server.IPublicDictServer;
import com.daz.student.pojo.InquireAnswerPojo;
import com.daz.student.server.IInquireAnswerServer;
import com.daz.teacher.teacherInfo.pojo.teacher;
import com.daz.teacher.teacherInfo.server.iTeacherServer;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class InquireAnswer extends ActionSupport{
	@Autowired
	public iTeacherServer teacherServer;
	@Autowired
	public IInquireAnswerServer inquireAnswerServer;
	@Autowired
	public IPublicDictServer publicDictServer;
	private List<String> answer;
	private Boolean success;
	private String msg;
	private String isHidden;
	private String other;
	private String jsonString;
	private List<InquireAnswerPojo> resultList;
	public String addInquireAnswer(){
		Map<String, Object> selectParamMap = new HashMap<>();
		Map<String, Object> session = ActionContext.getContext().getSession();
		selectParamMap.put("studentId", session.get("userId"));
		Map<String, Object> promMap = new HashMap<>();
		promMap.put("publicCode", "prom");
		List<SystemParam> promList;
		try {
		promList = publicDictServer.selectStatus(promMap);		
		selectParamMap.put("prom", promList.get(0).getValue().getValueName());	
		if(inquireAnswerServer.selectInquireAnswer(selectParamMap).size() <=0){
		long mark = 0;
		for(int i = 0;i<answer.size();i++){
			switch (answer.get(i)) {
			case "A":
				mark+=90;
				break;
			case "B":
				mark+=80;
				break;
			case "C":
				mark+=70;
				break;
			case "D":
				mark+=60;
				break;
			}
		}
		String markString = mark/answer.size()+"";
		InquireAnswerPojo inquireAnswerPojo = new InquireAnswerPojo();
		inquireAnswerPojo.setInquireAnswer(markString);
		inquireAnswerPojo.setStudentId((String)session.get("userId"));
		inquireAnswerPojo.setStudentName((String)session.get("userName"));
		inquireAnswerPojo.setOther(other);
		inquireAnswerPojo.setProm(promList.get(0).getValue().getValueName());
		inquireAnswerPojo.setIsHidden(isHidden);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("studentId", session.get("userId"));
		List<teacher> list = teacherServer.getTeacherInfo(map);
		if(list.size()>0){
			teacher t=list.get(0);
			inquireAnswerPojo.setTeacherId(t.getTeacherId());
			inquireAnswerServer.addInquireAnswer(inquireAnswerPojo);
			this.setSuccess(true);
		}
		else{
			this.setSuccess(false);
			this.setMsg("你还没有被分配到具体导师名下，不能进行问卷调查");
		}
		}else{
			System.out.println("cunzai ");
			this.setSuccess(false);
			this.setMsg("你已经提交了问卷调查，不能再提交");
		}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	public String searchInquireAnswer(){
		Map<String, Object> inquireMap = JsonToMap.toHashMap(jsonString);
		try {
			resultList = inquireAnswerServer.selectInquireAnswer(inquireMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	public List<String> getAnswer() {
		return answer;
	}
	public void setAnswer(List<String> answer) {
		this.answer = answer;
	}
	public Boolean getSuccess() {
		return success;
	}
	public void setSuccess(Boolean success) {
		this.success = success;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public String getIsHidden() {
		return isHidden;
	}
	public void setIsHidden(String isHidden) {
		this.isHidden = isHidden;
	}
	public String getOther() {
		return other;
	}
	public void setOther(String other) {
		this.other = other;
	}
	
	public String getJsonString() {
		return jsonString;
	}
	public void setJsonString(String jsonString) {
		this.jsonString = jsonString;
	}
	public List<InquireAnswerPojo> getResultList() {
		return resultList;
	}
	public void setResultList(List<InquireAnswerPojo> resultList) {
		this.resultList = resultList;
	}
	
	
}
